package com.example.warehouse.sys.controller;

import com.example.warehouse.common.web.JsonResult;
import com.example.warehouse.sys.pojo.vo.PermissionTreeItemVO;
import com.example.warehouse.sys.service.IPermissionService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sys/permission")
@Slf4j
@Validated
@Api(tags = "6.1. 权限管理")
public class PermissionController {

    public PermissionController() {
        log.info("");
    }

    @Autowired
    private IPermissionService permissionService;

    @GetMapping("/tree")
    /*@PreAuthorize("hasAuthority('/sys/permission/tree')")*/
    @ApiOperation("查询权限树")
    @ApiOperationSupport(order = 420)
    public JsonResult listTree() {
        log.debug("开始处理【获取权限树】的业务，参数：无");
        List<PermissionTreeItemVO> permissionTreeItemVOS = permissionService.listTree();
        return JsonResult.ok(permissionTreeItemVOS);
    }
}
